package com.tehui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowManager;

import com.tehui.R;

/**
 * Created by jasmine on 2017/7/14.
 */

public class CustomeUserNoticeCursor extends View {
    Paint mPaint;

    private Context context;

    private float i;

    public CustomeUserNoticeCursor(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        initRes();
    }

    private void initRes() {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        double v = width * 1.5;

        i = (float) (dp2px(context, 35) / v);
        mPaint = new Paint();
        mPaint.setColor(getResources().getColor(R.color.pink));
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setAntiAlias(true);
    }

    public CustomeUserNoticeCursor(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomeUserNoticeCursor(Context context) {
        this(context, null);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF rect3 = new RectF(i * cursorMoveX, dp2px(context, 0), i * cursorMoveX+ dp2px(context, 35), dp2px(context, 3));
        canvas.drawRect(rect3, mPaint);
    }

    private float cursorMoveX;

    public void SetOffSet(float cursorMoveX) {
        this.cursorMoveX = cursorMoveX;
        invalidate();
    }

    public static int dp2px(Context context, float dpValue) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}
